package io.renren.modules.health.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.health.dao.HmQuestionnaireDao;
import io.renren.modules.health.dto.HmQuestionnaireDTO;
import io.renren.modules.health.entity.HmQuestionnaireEntity;
import io.renren.modules.health.service.HmQuestionnaireService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 调查问卷测评结果
 *
 * @author  
 * @since 1.0.0 2024-04-08
 */
@Service
public class HmQuestionnaireServiceImpl extends CrudServiceImpl<HmQuestionnaireDao, HmQuestionnaireEntity, HmQuestionnaireDTO> implements HmQuestionnaireService {

    @Override
    public QueryWrapper<HmQuestionnaireEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        Long cusId = (Long)params.get("cusId");
        String orderFiled = (String)params.get("orderFiled");

        QueryWrapper<HmQuestionnaireEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.eq(cusId != null, "cus_id", cusId);
        wrapper.orderByDesc(StrUtil.isNotBlank(orderFiled),orderFiled);

        return wrapper;
    }


    /**
     * 根据客户id查询最新问卷结果
     * @param cusId
     * @return
     */
    @Override
    public List<HmQuestionnaireEntity> getNewestByCusId(Long cusId) {
        return this.baseDao.selectList(new QueryWrapper<HmQuestionnaireEntity>().eq("cus_id",cusId).orderByDesc("create_date"));
    }
}